﻿
(function () {
    appModule.controller('common.views.callPolices.detail', [
        '$scope', '$uibModalInstance', 'abp.services.app.callPolice', 'callPoliceId', 'abp.services.app.callType', 'abp.services.app.file', "$sce",
        function ($scope, $uibModalInstance, callPoliceService, callPoliceId, callTypeService, fileService, $sce) {
            var vm = this;
            vm.saving = false;
            //首先将callPolice数据设置为null
            vm.callPolice = null;
            vm.showAudio = false;
            vm.showVideo = false;
            vm.showDetail = false;
            //$sce.trustAs(type, name);
            //$sce.trustAsHtml(value);
            //$sce.trustAsUrl(value);
            //$sce.trustAsResourceUrl(value);
            //$sce.trustAsJs(value);

            //文件路径处理 
            vm.fileUrl = function (url) {
                return $sce.trustAsResourceUrl(url);
            } 

            //取消关闭页面
            vm.cancel = function () {
                $uibModalInstance.dismiss();
            };

            //change事件
            vm.callTypeChange = function (val) {
                if (val == 1) {
                    vm.showAudio = true;
                    vm.showVideo = false;
                    vm.showDetail = false;
                }
                else if (val == 2) {
                    vm.showAudio = false;
                    vm.showVideo = true;
                    vm.showDetail = false;
                }
                else {
                    vm.showAudio = false;
                    vm.showVideo = false;
                    vm.showDetail = true;
                }
            };

            //初始化页面
            function init() {

                //绑定一键报警分类
                callTypeService.getAllCallTypeList().then(function (result) {
                    vm.callTypeList = result.data.items;

                    callPoliceService.getCallPoliceForEditAsync({
                        id: callPoliceId
                    }).then(function (result) {
                        vm.callPolice = result.data.callPolice;

                        vm.callTypeChange(vm.callPolice.callTypeID);
                    });
                });

            }
            //执行初始化方法
            init();
        }
    ]);
})();